//
//  ZJExtensionMoneyAccountVC.m
//  这家测试项目
//
//  Created by IOS_DEVELOPER on 2017/7/20.
//  Copyright © 2017年 陈志凌. All rights reserved.
//

#import "ZJExtensionMoneyAccountVC.h"
#import "ZJExtensionMoneyAccountCell.h"

@interface ZJExtensionMoneyAccountVC (){
    NSInteger page;
}
@property (weak, nonatomic) IBOutlet UIImageView *headImg;
@property (weak, nonatomic) IBOutlet UIView *headview;
@property (strong, nonatomic) NSMutableArray * dataArr;
@end

@implementation ZJExtensionMoneyAccountVC

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.headImg.image = [UIImage imageNamed:kHeadImgName];
    self.headview.backgroundColor = [Utils colorWithHexString:allConstHexColor];
    page = 1;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([ZJExtensionMoneyAccountCell class]) bundle:nil] forCellReuseIdentifier:@"ZJExtensionMoneyAccountCell"];
    [self sendRequest];
    [self setupRefresh];
}

- (void)setupRefresh
{
    WEAK_SELF
    [self.tableView setRefreshWithHeaderBlock:nil footerBlock:^{
        STRONG_SELF
        page ++;
        [strongSelf sendRequest];
    }];
    
}

#pragma mark - ******************请求数据
-(void)sendRequest{
    [HUD showLoading:@"加载数据中..."];
    NSDictionary *parameter = [LRNetwork requestParameter:@{@"p":@(page)}];
    NSString *url = [LRNetwork requestURL:@"cgi/customer.php"];
    
    [LRNetwork netRequestPOSTWithRequestURL:url withParameter:parameter withReturnValeuBlock:^(id returnValue) {
        
        NSArray *arr = returnValue[@"customer"];
        if (page == 1) {
            self.dataArr = arr.mutableCopy;
        } else {
            [self.dataArr addObjectsFromArray:arr];
        }
        if (!self.dataArr) {
            self.dataArr = arr.mutableCopy;
        }
        [self.tableView reloadData];
        [HUD hide];
    } withErrorCodeBlock:^(NSInteger errorCode, NSString *errorMessage) {
        [HUD showErrorMsg:errorMessage];
    } withFailureBlock:^{
        
    }];
    
    [self.tableView headerEndRefreshing];
    [self.tableView footerEndRefreshing];
}

#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
     [tableView tableViewDisplayWitMsg:kNoDataImgName ifNecessaryForRowCount:self.dataArr.count];
    return self.dataArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZJExtensionMoneyAccountCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZJExtensionMoneyAccountCell"];
    NSDictionary * dict = self.dataArr[indexPath.row];
    cell.install.text = dict[@"install"];
    cell.deposit.text = dict[@"deposit"];
    cell.name.text = dict[@"realname"];
    cell.deal.text = dict[@"deal"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    if (indexPath.row %2 !=0) {
        cell.contentView.backgroundColor = RGB(247, 247, 247);
    }
    
    [cell useCellFrameCacheWithIndexPath:indexPath tableView:tableView];
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
}
@end
